{foreach from=$comments item=row name=rows}
{assign var=comment value=$row.parent}
{assign var=subComments value=$row.subComments}
{assign var=user value=$comment->user}
{assign var=scores value=$row.votes}
{assign var=avgScore value=0}
{foreach from=$scores item=score name=avg}
		{assign var=avgScore value=$avgScore+$score->getRate()}
{/foreach}
{if $smarty.foreach.avg.total gt 0}
	{assign var=avgScore value=$avgScore/$smarty.foreach.avg.total|number_format:2}
{else}
	{assign var=avgScore value='0'}
{/if}
{if $user|is_object}
	<div class="opitionItem">

		<div class="userTitle">
			<a href="{url label=userProfile idUser=$user->getId()}" title="Username"><img src="{$urlStatic}/{image src=$user->getAvatar() w=50 h=50}" alt="{$user->getLastName()}" class="thumb"/></a>
			<h2>{$comment->getTitle()|wordwrap:50:"\n":true}</h2>
			<p class="date">{$comment->getDate()|date_format:"%Y-%m-%d"}</p>
			{'by'|t} <a href="{url label=userProfile idUser=$user->getId()}" title="{$user->getLastName()}">{$user->getFirstName()} {$user->getLastName()}<br/><img src="{$urlStatic}/image/Strona/rank3.png" alt="rank"/></a>
            <div class="cb"></div>
		</div>

		<div class="opinionScorePanel">
			<h5>{'Opinion overview'|t}</h5>
			<table class="overview">
					<tr>
						<td>{'Rate'|t}</td>
						<td class="valueRate">{$avgScore}</td>
					</tr>
				{foreach from=$scores item=score}
					<tr>
						<td>{$score->productVotesType->getName()|t}</td>
						<td class="value"><img src="{$urlStatic}/image/Strona/score{$score->getRate()}.png" alt="score{$score->getRate()}"></td>
					</tr>
				{/foreach}
			</table>

			<h5>{'Rate this opinion'|t}</h5>
			<p>
				<a href="{url label=rateComment action=like id=$comment->getId()}" title="{'good opinion'|t}" class="handUp rateComment">{$comment->getLikes()}</a>
				<a href="{url label=rateComment action=dislike id=$comment->getId()}" title="{'bad opinion'|t}" class="handDown rateComment">{$comment->getDisLikes()}</a>
			</p>
			<p>
				{assign var=likes value=$comment->getLikes()}
				{assign var=dislikes value=$comment->getDisLikes()}
				{assign var=sum value=$likes+$dislikes}
				{if $sum gt 0}
					{assign var=percent value=$likes/$sum*100}
					{$percent|ceil}% ({$likes} {'of'|t} {$sum}) {'rated this opinion to be useful.'|t}
				{/if}
				
			</p>
		</div>

		{$comment->getContent()|wordwrap:50:"\n":true}

		<div class="clearBoth"></div>
		
		<div class="commentBar" id="commentBar{$comment->getId()}">
			<a class="aComments aComments_" title="comments"><span>{$subComments|@count}</span> {'comments'|t}</a>
			{if $_userLoggedIn}
			<a class="addComment" title="comments">{'write your comment'|t}</a>			
			<a class="reportComment _reportComment" href="{url label=reportAbuse id=$comment->getId()}" title="{'report abuse'|t}">{'report abuse'|t}</a>
			{/if}
		</div>
		
		{foreach from=$subComments item=row}
			{assign var=subUser value=$row->user}
			<div class="comments">
			<div class="userAvatar"><a href="{url label=userProfile idUser=$subUser->getId()}" title="Username"><img src="{$urlStatic}/{image src=$subUser->getAvatar() w=30 h=30}"  alt="Username" title="Username" class="avatar"/></a></div>
			<div class="message">
				<p class="date">{$row->getDate()|date_format:"%Y-%m-%d"}</p>
				<p class="username"><a href="{url label=userProfile idUser=$subUser->getId()}" title="Username">{$subUser->getFirstName()} {$subUser->getLastName()}</a></p>
				<p>{$row->getContent()|wordwrap:30:"\n":true}</p>
				{if $_userLoggedIn}
				<p>	<a href="{url label=reportAbuse id=$comment->getId()}" class="reportComment _reportComment" title="{'report abuse'|t}">{'report abuse'|t}</a></p>
				{/if}
			</div>
			<div class="clearBoth"></div>
		</div>
		{/foreach}

		<div class="newCommentContainer newCommentContainer{$comment->getId()} hidden">

		</div>
	
		{if $_user|is_object}
		<div class="comments commentsNewMessage">
			<form action="{url label=subComment}" method="post" class="subComment" name="subComment{$comment->getId()}">
				<div class="userAvatar">
					<a href="{url label=userProfile idUser=$_user->getId()}" title="{$_user->getFirstName()} {$_user->getLastName()}">
						<img src="{$urlStatic}/{image src=$_user->getAvatar() w=30 h=30}"  alt="{$_user->getFirstName()} {$_user->getLastName()}" title="{$_user->getFirstName()} {$_user->getLastName()}" class="avatar"/>
					</a>
				</div>
				<div class="message">
					<textarea name="comment-content" class="focusin" rows="5" cols="20" rel="{'enter text...'|t}">{'enter text...'|t}</textarea>
				</div>
				<div class="submit">
					<input type="submit" class="button" name="submit"  value="{'Send'|t}" />
				</div>
				<input type="hidden" name="parent" value="{$comment->getId()}" />
				<input type="hidden" name="product" value="{$comment->getIdContent()}" />
			</form>
			<div class="clearBoth"></div>
		</div>
		{/if}
		<!-- opinionItem -->
	</div>
		{/if}
{foreachelse} 
	<div class="opitionItem">
	<h2>{'Brak produktów spełniających podane kryteria'|t}</h2>
	</div>
	
{/foreach}


